package org.phantom.demo.integration.impl;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.Socket;

import org.phantom.demo.integration.SocketClient;
import org.springframework.stereotype.Service;

@Service("socketService")
public class SocketClientImpl implements SocketClient {
	private Socket socket = null; 
	@Override
	public String sendName(String name) {
		try {
			 socket = new Socket("localhost", 9527);
			 //读取服务器端数据    
             DataInputStream input = new DataInputStream(socket.getInputStream());    
             //向服务器端发送数据    
             DataOutputStream out = new DataOutputStream(socket.getOutputStream());    
             out.writeUTF(name);    
             String ret = input.readUTF();
             return ret;
		} catch (Exception e) {
		}finally{
			if(socket!=null)
				try {
					socket.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
		}
		return null;
	}

}
